﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using uTrade.Core;

namespace uTrade.Strategies
{
    public class CommonApi
    {
        /// <summary>
        /// 获取当前dll里面的所有策略
        /// </summary>
        /// <returns></returns>
        public static List<Type> GetAllStrategies()
        {
            List<Type> lstStrag = new List<Type>();
            string dllPath = Path.GetFullPath(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            try
            {
                Assembly ass = Assembly.LoadFile(dllPath);
                //加载hf_plat报错:增加对hf_plat_core的引用
                foreach (var t in ass.GetTypes())
                {
                    if (t.BaseType == typeof(Strategy))
                    {
                        lstStrag.Add(t);
                    }
                }
            }
            catch (Exception err)
            {
                throw new Exception("获取策略集合失败：" + err.ToString());
            }

            return lstStrag;
        }

        public static Type GetStrategy(string type)
        {
            return Type.GetType(type);
        }
    }
}